package com.test;

public class demo1 {
    public static void main(String[] args) {
        ThreadTicket threadTicket = new ThreadTicket();
        new Thread(threadTicket, "窗口1").start();
        new Thread(threadTicket, "窗口2").start();
        new Thread(threadTicket, "窗口3").start();
        new Thread(threadTicket, "窗口4").start();
    }
}

class ThreadTicket implements Runnable {
    int ticks = 100;
    boolean f = true;

    @Override
    public void run() {
            while (f) {
                synchronized (this) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (ticks > 0) {
                    System.out.println(Thread.currentThread() + "买100张的第" + ticks-- + "张");
                }
                if (ticks == 0) {
                    f = false;
                }
            }
        }

    }
}
